<?php

namespace App\Http\Resources;

use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;

class CelueResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
       $item= $this->resource;
        /**
         * @var $item \App\Models\Celue
         */
        return [
          'code'=>200,
          'message'=>'请求成功',
          'data'=>[
                'id'=>$item->id,
                'title'=>$item->title,
                'jianjie'=>$item->jianjie,
                'logo'=>$item->logo ? \Storage::url($item->logo) :'',
                'detail'=>$item->detail,
                'view_num'=>$item->view_num,
              'created_at'=>Carbon::parse($item->created_at)->format('Y-m-d H:i:s'),
          ]
        ];
    }
}
